// components/time-step/time-step.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {
    normalSrc:'../../assets/images/time-step1.png',
    selectedSrc:'../../assets/images/time-step2.png',
    stepData:[
      {
        stepName:'上午',
        selectedSrc:'',
        value:'上午'
      },
      {
        stepName:'中午',
        selectedSrc:'',
        value:'上午'
      },
      {
        stepName:'下午',
        selectedSrc:'',
        value:'上午'
      }
    ]
  },
  lifetimes:{
    attached: function(){
      this.data.stepData.forEach((item,i) => {
        this.setData({
          ['stepData['+i+'].selectedSrc']:this.data.normalSrc
        })
      })
      console.log(this.data)
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    selectStep(e){
      let index = e.currentTarget.dataset.index
      this.data.stepData.forEach((item,i) => {
        this.setData({
          ['stepData['+i+'].selectedSrc']:this.data.normalSrc
        })
      })
      /*  */
      this.setData({
        ['stepData['+index+'].selectedSrc']:this.data.selectedSrc
      })
      /*  */
      this.triggerEvent('setTimeStepValue',{
        value:this.data.stepData[index].value
      })
    }
  }
})
